﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace HYRElectric.WirePlace
{
	public partial class DlgSetSCEHigh : System.Windows.Forms.Form
	{
		public DlgSetSCEHigh()
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			string text = null;
			string text2 = null;
			this.textCeilingTop.Text = "200";
			this.textFloorBot.Text = "200";
			DlgSetSCEHigh.ReadXml(ref text, ref text2);
			if (text != null && text != "")
			{
				this.textCeilingTop.Text = text;
			}
			if (text2 != null && text2 != "")
			{
				this.textFloorBot.Text = text2;
			}
		}

		private void textCeilingTop_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar != '\b' && (e.KeyChar < '0' || e.KeyChar > '9'))
			{
				e.Handled = true;
			}
		}

		private void textFloorBot_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar != '\b' && (e.KeyChar < '0' || e.KeyChar > '9'))
			{
				e.Handled = true;
			}
		}

		public static void ReadXml(ref string sCeilintTop, ref string sFloorTop)
		{
			string text = Path.GetTempPath() + "DlgSetSCEHigh.xml";
			if (!File.Exists(text))
			{
				return;
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text);
			XmlNode xmlNode = xmlDocument.SelectSingleNode("HighValue");
			sCeilintTop = xmlNode.Attributes[0].Value;
			sFloorTop = xmlNode.Attributes[1].Value;
		}

		private void SaveXml()
		{
			string filename = Path.GetTempPath() + "DlgSetSCEHigh.xml";
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement xmlElement = xmlDocument.CreateElement("HighValue");
			xmlDocument.AppendChild(xmlElement);
			xmlElement.SetAttribute(DlgSetSCEHigh.strCeilingTop, this.textCeilingTop.Text);
			xmlElement.SetAttribute(DlgSetSCEHigh.strFloorBot, this.textFloorBot.Text);
			xmlDocument.Save(filename);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.textCeilingTop.Text == null || this.textCeilingTop.Text == "" || this.textFloorBot.Text == null || this.textFloorBot.Text == "")
			{
				YJKMessageBox.Show("输入数字不能为空！");
				return;
			}
			this.SaveXml();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private static string strCeilingTop = "吊顶上";

		private static string strFloorBot = "顶板下";
	}
}
